package com.example.teliaCellInfo;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;

public class CanvasView extends View {

	private Paint paint = new Paint();
	private Paint squarePaint = new Paint();
	private Paint crossPaint = new Paint();
	private double bars;
	private String type;
	private int x;
	private int y;
	private int lastX;
	private int lastY;

	public CanvasView(Context context, int value, String signalType) {
		super(context);
		bars = value;
		type = signalType;
	}

	public int count(int x, double d) {
		int c = (int) (x * d);

		return c;
	}

	@Override
	protected void onDraw(android.graphics.Canvas canvas) {
		super.onDraw(canvas);

		canvas.drawColor(Color.WHITE);
		

		x = (int) ((float) getWidth() / 6.35);
		y = (int) ((float) getHeight() / 1.73);
		lastX = (int) ((float) getWidth() / 4.32);
		lastY = (int) ((float) getHeight() / 1.2);

		paint.setStrokeWidth(count(lastX, 0.32));
		paint.setColor(Color.argb(255, 101, 45, 134));

		squarePaint.setStrokeWidth(5);
		squarePaint.setColor(Color.argb(200, 90, 49, 131));
		squarePaint.setStyle(Paint.Style.STROKE);

		crossPaint.setStrokeWidth(count(lastX, 0.25));
		crossPaint.setColor(Color.argb(255, 216, 0, 0));

		canvas.drawRect(count(x, 1), count(y, 1), count(lastX, 1), lastY,
				squarePaint);
		canvas.drawRect(count(x, 1.65), count(y, 0.875), count(lastX, 1.44),
				lastY, squarePaint);
		canvas.drawRect(count(x, 2.29), count(y, 0.75), count(lastX, 1.88),
				lastY, squarePaint);
		canvas.drawRect(count(x, 2.94), count(y, 0.625), count(lastX, 2.32),
				lastY, squarePaint);
		canvas.drawRect(count(x, 3.59), count(y, 0.5), count(lastX, 2.76),
				lastY, squarePaint);
		canvas.drawRect(count(x, 4.235), count(y, 0.375), count(lastX, 3.2),
				lastY, squarePaint);
		canvas.drawRect(count(x, 4.882), count(y, 0.25), count(lastX, 3.65),
				lastY, squarePaint);

		if (type == "WCDMA" || type == "GSM") {

			if (bars == -130 || bars == 0) {
				canvas.drawLine(count(x, 1.3), count(y, 1.03),
						count(lastY, 1.4), count(y, 0.32), crossPaint);
				canvas.drawLine(count(x, 1.3), count(y, 0.32),
						count(lastY, 1.4), count(y, 1.03), crossPaint);

			}

			if (bars > -129 && bars <= -120) {
				canvas.drawLine(count(x, 0.235) + x, lastY,
						count(x, 0.235) + x, y, paint);
			}

			if (bars >= -120 && bars <= -110) {
				canvas.drawLine(count(x, 0.235) + x, lastY,
						count(x, 0.235) + x, y, paint);
				canvas.drawLine(count(x, 0.88) + x, lastY, count(x, 0.88) + x,
						count(y, 0.875), paint);
			}

			if (bars >= -110 && bars <= -100) {
				canvas.drawLine(count(x, 0.235) + x, lastY,
						count(x, 0.235) + x, y, paint);
				canvas.drawLine(count(x, 0.88) + x, lastY, count(x, 0.88) + x,
						count(y, 0.875), paint);
				canvas.drawLine(count(x, 1.53) + x, lastY, count(x, 1.53) + x,
						count(y, 0.75), paint);
			}

			if (bars >= -100 && bars <= -90) {
				canvas.drawLine(count(x, 0.235) + x, lastY,
						count(x, 0.235) + x, y, paint);
				canvas.drawLine(count(x, 0.88) + x, lastY, count(x, 0.88) + x,
						count(y, 0.875), paint);
				canvas.drawLine(count(x, 1.53) + x, lastY, count(x, 1.53) + x,
						count(y, 0.75), paint);
				canvas.drawLine(count(x, 2.176) + x, lastY,
						count(x, 2.176) + x, count(y, 0.625), paint);
			}

			if (bars >= -90 && bars <= -80) {
				canvas.drawLine(count(x, 0.235) + x, lastY,
						count(x, 0.235) + x, y, paint);
				canvas.drawLine(count(x, 0.88) + x, lastY, count(x, 0.88) + x,
						count(y, 0.875), paint);
				canvas.drawLine(count(x, 1.53) + x, lastY, count(x, 1.53) + x,
						count(y, 0.75), paint);
				canvas.drawLine(count(x, 2.176) + x, lastY,
						count(x, 2.176) + x, count(y, 0.625), paint);
				canvas.drawLine(count(x, 2.82) + x, lastY, count(x, 2.82) + x,
						count(y, 0.5), paint);
			}

			if (bars >= -80 && bars <= -70) {
				canvas.drawLine(count(x, 0.235) + x, lastY,
						count(x, 0.235) + x, y, paint);
				canvas.drawLine(count(x, 0.88) + x, lastY, count(x, 0.88) + x,
						count(y, 0.875), paint);
				canvas.drawLine(count(x, 1.53) + x, lastY, count(x, 1.53) + x,
						count(y, 0.75), paint);
				canvas.drawLine(count(x, 2.176) + x, lastY,
						count(x, 2.176) + x, count(y, 0.625), paint);
				canvas.drawLine(count(x, 2.82) + x, lastY, count(x, 2.82) + x,
						count(y, 0.5), paint);
				canvas.drawLine(count(x, 3.47) + x, lastY, count(x, 3.47) + x,
						count(y, 0.375), paint);
			}

			if (bars >= -70 && bars <= -50) {

				canvas.drawLine(count(x, 0.235) + x, lastY,
						count(x, 0.235) + x, y, paint);
				canvas.drawLine(count(x, 0.88) + x, lastY, count(x, 0.88) + x,
						count(y, 0.875), paint);
				canvas.drawLine(count(x, 1.53) + x, lastY, count(x, 1.53) + x,
						count(y, 0.75), paint);
				canvas.drawLine(count(x, 2.176) + x, lastY,
						count(x, 2.176) + x, count(y, 0.625), paint);
				canvas.drawLine(count(x, 2.82) + x, lastY, count(x, 2.82) + x,
						count(y, 0.5), paint);
				canvas.drawLine(count(x, 3.47) + x, lastY, count(x, 3.47) + x,
						count(y, 0.375), paint);
				canvas.drawLine(count(x, 4.12) + x, lastY, count(x, 4.12) + x,
						count(y, 0.25), paint);

			}

		}

		if (type == "LTE") {

			if (bars == -140 || bars == -0) {
				canvas.drawLine(count(x, 1.3), count(y, 1.03),
						count(lastY, 1.4), count(y, 0.32), crossPaint);
				canvas.drawLine(count(x, 1.3), count(y, 0.32),
						count(lastY, 1.4), count(y, 1.03), crossPaint);

			}

			if (bars > -140 && bars <= -126.2) {
				canvas.drawLine(count(x, 0.235) + x, lastY,
						count(x, 0.235) + x, y, paint);
			}

			if (bars >= -126.2 && bars <= -112.5) {
				canvas.drawLine(count(x, 0.235) + x, lastY,
						count(x, 0.235) + x, y, paint);
				canvas.drawLine(count(x, 0.88) + x, lastY, count(x, 0.88) + x,
						count(y, 0.875), paint);
			}

			if (bars >= -112.5 && bars <= -98.8) {
				canvas.drawLine(count(x, 0.235) + x, lastY,
						count(x, 0.235) + x, y, paint);
				canvas.drawLine(count(x, 0.88) + x, lastY, count(x, 0.88) + x,
						count(y, 0.875), paint);
				canvas.drawLine(count(x, 1.53) + x, lastY, count(x, 1.53) + x,
						count(y, 0.75), paint);
			}

			if (bars >= -98.8 && bars <= -85.1) {
				canvas.drawLine(count(x, 0.235) + x, lastY,
						count(x, 0.235) + x, y, paint);
				canvas.drawLine(count(x, 0.88) + x, lastY, count(x, 0.88) + x,
						count(y, 0.875), paint);
				canvas.drawLine(count(x, 1.53) + x, lastY, count(x, 1.53) + x,
						count(y, 0.75), paint);
				canvas.drawLine(count(x, 2.176) + x, lastY,
						count(x, 2.176) + x, count(y, 0.625), paint);
			}

			if (bars >= -85.1 && bars <= -71.4) {
				canvas.drawLine(count(x, 0.235) + x, lastY,
						count(x, 0.235) + x, y, paint);
				canvas.drawLine(count(x, 0.88) + x, lastY, count(x, 0.88) + x,
						count(y, 0.875), paint);
				canvas.drawLine(count(x, 1.53) + x, lastY, count(x, 1.53) + x,
						count(y, 0.75), paint);
				canvas.drawLine(count(x, 2.176) + x, lastY,
						count(x, 2.176) + x, count(y, 0.625), paint);
				canvas.drawLine(count(x, 2.82) + x, lastY, count(x, 2.82) + x,
						count(y, 0.5), paint);
			}

			if (bars >= -71.4 && bars <= -57.7) {
				canvas.drawLine(count(x, 0.235) + x, lastY,
						count(x, 0.235) + x, y, paint);
				canvas.drawLine(count(x, 0.88) + x, lastY, count(x, 0.88) + x,
						count(y, 0.875), paint);
				canvas.drawLine(count(x, 1.53) + x, lastY, count(x, 1.53) + x,
						count(y, 0.75), paint);
				canvas.drawLine(count(x, 2.176) + x, lastY,
						count(x, 2.176) + x, count(y, 0.625), paint);
				canvas.drawLine(count(x, 2.82) + x, lastY, count(x, 2.82) + x,
						count(y, 0.5), paint);
				canvas.drawLine(count(x, 3.47) + x, lastY, count(x, 3.47) + x,
						count(y, 0.375), paint);
			}

			if (bars >= -57.7 && bars <= -44) {

				canvas.drawLine(count(x, 0.235) + x, lastY,
						count(x, 0.235) + x, y, paint);
				canvas.drawLine(count(x, 0.88) + x, lastY, count(x, 0.88) + x,
						count(y, 0.875), paint);
				canvas.drawLine(count(x, 1.53) + x, lastY, count(x, 1.53) + x,
						count(y, 0.75), paint);
				canvas.drawLine(count(x, 2.176) + x, lastY,
						count(x, 2.176) + x, count(y, 0.625), paint);
				canvas.drawLine(count(x, 2.82) + x, lastY, count(x, 2.82) + x,
						count(y, 0.5), paint);
				canvas.drawLine(count(x, 3.47) + x, lastY, count(x, 3.47) + x,
						count(y, 0.375), paint);
				canvas.drawLine(count(x, 4.12) + x, lastY, count(x, 4.12) + x,
						count(y, 0.25), paint);

			}

		}
	}
}
